/*
 * server2.cpp
 *
 *  Created on: May 17, 2011
 *      Author: madboyka
 */

#include "Server.h"
#include <signal.h>
#include "Logger.h"

/*!
 * Signal handler for SIGINT SIGSEGV SIGPIPE SIGHUP SIGTERM.
 */
void signalHandler(int signum) {
	QString msg("Got signal: ");
	switch (signum) {
	case SIGINT:
		msg.append("SIGINT");
		break;
	case SIGSEGV:
		msg.append("SIGSEGV");
		break;
	case SIGPIPE:
		msg.append("SIGPIPE");
		break;
	case SIGHUP:
		msg.append("SIGHUP");
		break;
	case SIGTERM:
		msg.append("SIGTERM");
		break;
	}
	Logger::error(msg);
	Server::kill();
}

/*!
 * main function lol.
 */
int main(int argc, char *argv[]) {

	if (signal(SIGINT, signalHandler) == SIG_IGN)
		signal(SIGINT, SIG_IGN);
	if (signal(SIGSEGV, signalHandler) == SIG_IGN)
		signal(SIGSEGV, SIG_IGN);
	if (signal(SIGPIPE, signalHandler) == SIG_IGN)
		signal(SIGPIPE, SIG_IGN);
	if (signal(SIGHUP, signalHandler) == SIG_IGN)
		signal(SIGHUP, SIG_IGN);
	if (signal(SIGTERM, signalHandler) == SIG_IGN)
		signal(SIGTERM, SIG_IGN);
	Logger::init("server.log");
	Server *server = new Server();
	server->setup();

}
